package webapp.mvc.services.impl;

import cn.apiclub.captcha.text.producer.NumbersAnswerProducer;
import cn.apiclub.captcha.text.producer.TextProducer;
import org.springframework.stereotype.Service;
import webapp.mvc.models.CaptchaRequestEntity;
import webapp.mvc.services.ICaptchaService;

@Service
public class CaptchaService implements ICaptchaService {
    @Override
    public CaptchaRequestEntity newCaptchaRequest() {
        TextProducer producer = new NumbersAnswerProducer(4);
        String text = producer.getText();
        CaptchaRequestEntity captchaRequest = new CaptchaRequestEntity();
        captchaRequest.setAnswer(text);
        captchaRequest.save();
        return captchaRequest;
    }

    @Override
    public CaptchaRequestEntity findById(String id) {
        return CaptchaRequestEntity.find.byId(id);
    }
}
